package com.tr.rentcar.controller.houtai.car;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONArray;
import com.tr.rentcar.model.bean.CarBrand;
import com.tr.rentcar.model.bean.CarStyle;
import com.tr.rentcar.model.bean.CarUse;
import com.tr.rentcar.model.bean.Cars;
import com.tr.rentcar.model.dao.CarBrandDao;
import com.tr.rentcar.model.dao.CarInfoDao;
import com.tr.rentcar.model.dao.CarStyleDao;
import com.tr.rentcar.model.dao.CarUseDao;
@WebServlet("/carstorexiugai")
public class CarstorexiugaiControllor extends HttpServlet {
	CarInfoDao CarInfoDao=new CarInfoDao();
	Cars Cars=new Cars();
	CarBrandDao cb=new CarBrandDao();
	CarStyleDao cs=new CarStyleDao();
	CarUseDao cu=new CarUseDao();
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	 try {
		 String id=req.getParameter("id");
		 String pid=req.getParameter("pid");
		 req.setAttribute("pid", pid);
		 Cars Cars=CarInfoDao.getInfoById(id);
		 req.setAttribute("Cars", Cars);
		 List<CarBrand> carbrand=cb.getAll();
		 List<CarStyle> carstyle=cs.getAll();
		 List<CarUse> caruse=cu.getAll();
		 req.setAttribute("carbrand", carbrand);
		 req.setAttribute("carstyle", carstyle);
		 req.setAttribute("caruse", caruse);
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	req.getRequestDispatcher("/WEB-INF/jsp/houtai_carstoremodify.jsp").forward(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	int cid=Integer.parseInt( req.getParameter("cid"));
	String lei=req.getParameter("lei");
	String shu=req.getParameter("shu");
	//System.out.println(cid+"|"+shu+"|"+lei);
	try {
		if (lei.equals("cjingpin")) {
			CarInfoDao.update8(cid, shu);
		}
		if (lei.equals("cnew")) {
			CarInfoDao.update6(cid, shu);
		}
		if (lei.equals("chot")) {
			CarInfoDao.update7(cid, shu);
		}
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
}
}




